const app = getApp()
Page({
  data: {
    imgurl: app.globalData.imgurl,
    city: [],
    active: 0,
    list: [],
  },
  onLoad(option) {
    this._getArea()
  },

  // 获取城市列表
  async _getArea() {
    let { code, data } = await wx.requestAsync({
      url: '/shop/area',
    })
    if (code == 0) {
      console.log(data)
      this.setData({
        city: data,
      })
      this._cityList()
    }
  },
  // tabs切换
  _tapTabs(e) {
    let { index } = e.detail
    let { active } = this.data
    this.setData({
      active: index,
    })
    if (active != index) {
      this._cityList()
    }
  },
  // 获取当前城市下的列表
  async _cityList() {
    let { active, city } = this.data
    let { code, data } = await wx.requestAsync({
      url: '/game/parent',
      data: {
        page: 1,
        type: city[active].type,
        code: city[active].code,
      },
    })
    if (code == 0) {
      let list = data.map((item) => {
        item.pic = this.imgurl = item.pic
        item.dz = item.p_name + item.c_name + item.a_name + item.address
        return item
      })
      console.log(list)
      this.setData({ list })
    }
  },
  _toLink({
    currentTarget: {
      dataset: { id },
    },
  }) {
    wx.navigateTo({
      url: '/pages/parentgame/parentgame?s_id=' + id,
    })
  },
  // 去预约
  _toReservation({
    currentTarget: {
      dataset: { id },
    },
  }) {
    wx.navigateTo({
      url: '/pages/pay/pay?s_id=' + id,
    })
  },
})
